package com.faithbj.device.web.controller.admin;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.faithbj.device.model.configuration.Pager;
import com.faithbj.device.model.entity.Members;
import com.faithbj.device.service.MemberService;
import com.faithbj.device.utils.SystemConfigUtil;


/**
 * 后台Action类 - 管理中心基类
 * <p>Copyright: Copyright (c) 2011</p> 
 * 
 * <p>Company: www.faithbj.com</p>
 * 
 * @author 	faithbj
 * @date 	2011-12-16
 * @version 1.0
 */

public class BaseAdminController implements Serializable{

	private static final long serialVersionUID = 6718838822334455667L;
	/**
	 * 返回成功页面
	 */
	protected final String SUCCESS="admin/success";
	protected final String ERROR="admin/error";
	
	protected Pager pager;
	
	@Resource
	protected SystemConfigUtil systemConfigUtil;
	@Resource
	protected MemberService memberService;
	
	protected void addSystemConfig(ModelMap map) {
		map.put("setting", systemConfigUtil);
	}
	
   @InitBinder  
    protected void initBinder(WebDataBinder binder) {  
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
        dateFormat.setLenient(false);  
        binder.registerCustomEditor(Date.class,new CustomDateEditor(dateFormat, false));  
    }  
	
	/**
	 * 获得登陆用户的用户名(无参)
	 * @param map
	 * @return
	 */
	protected Members getLoginMember() {
		Object memberObject = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		if(memberObject instanceof Members)
			return (Members)memberObject;
		else
			return null;
	}


}
